package cn.shop.dys.util;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
/**
 *
 * 首选项处理工具
 * Created by sunjian on 2016/4/18.
 *
 */
public class SPUtil {
	public static SharedPreferences getSharedPreferences(Context context) {
		SharedPreferences sp = context.getSharedPreferences("config",
				Context.MODE_PRIVATE);
		return sp;
	}

	public static void put(Context context, String key, Object value) {
		SharedPreferences sp = getSharedPreferences(context);
		Editor editor = sp.edit();
		if (value instanceof String) {
			editor.putString(key, (String) value);
		} else if (value instanceof Boolean) {
			editor.putBoolean(key, (Boolean) value);
		} else if (value instanceof Integer) {
			editor.putInt(key, (Integer) value);
		}
		editor.commit();
	}
	public static String getString(Context context, String key){
		SharedPreferences sp = getSharedPreferences(context);
		return sp.getString(key, "");
	}
	public static String getString(Context context, String key, String value){
		SharedPreferences sp = getSharedPreferences(context);
		return sp.getString(key, value);
	}
	public static boolean getBoolean(Context context, String key){
		SharedPreferences sp = getSharedPreferences(context);
		return sp.getBoolean(key, false);
	}
	public static int getInt(Context context, String key){
		SharedPreferences sp = getSharedPreferences(context);
		return sp.getInt(key, 0);
	}

}
